from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-22 14:02:53.264048
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 22, Nov, 2022
Time: 14:03:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.0201
Nobs: 848.000 HQIC: -51.3307
Log likelihood: 11106.6 FPE: 4.20369e-23
AIC: -51.5235 Det(Omega_mle): 3.78275e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299225 0.050418 5.935 0.000
L1.Burgenland 0.109693 0.034651 3.166 0.002
L1.Kärnten -0.106187 0.018460 -5.752 0.000
L1.Niederösterreich 0.210242 0.072448 2.902 0.004
L1.Oberösterreich 0.100917 0.068892 1.465 0.143
L1.Salzburg 0.251807 0.036737 6.854 0.000
L1.Steiermark 0.037366 0.048176 0.776 0.438
L1.Tirol 0.107480 0.039055 2.752 0.006
L1.Vorarlberg -0.060349 0.033666 -1.793 0.073
L1.Wien 0.054010 0.061553 0.877 0.380
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068083 0.103983 0.655 0.513
L1.Burgenland -0.030159 0.071465 -0.422 0.673
L1.Kärnten 0.047745 0.038073 1.254 0.210
L1.Niederösterreich -0.173308 0.149418 -1.160 0.246
L1.Oberösterreich 0.378806 0.142086 2.666 0.008
L1.Salzburg 0.288452 0.075767 3.807 0.000
L1.Steiermark 0.108242 0.099360 1.089 0.276
L1.Tirol 0.316026 0.080549 3.923 0.000
L1.Vorarlberg 0.022806 0.069433 0.328 0.743
L1.Wien -0.020328 0.126948 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197671 0.026103 7.573 0.000
L1.Burgenland 0.092590 0.017940 5.161 0.000
L1.Kärnten -0.008740 0.009557 -0.914 0.360
L1.Niederösterreich 0.268368 0.037508 7.155 0.000
L1.Oberösterreich 0.114846 0.035668 3.220 0.001
L1.Salzburg 0.052748 0.019020 2.773 0.006
L1.Steiermark 0.016747 0.024942 0.671 0.502
L1.Tirol 0.098589 0.020220 4.876 0.000
L1.Vorarlberg 0.055927 0.017430 3.209 0.001
L1.Wien 0.112273 0.031868 3.523 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104819 0.026772 3.915 0.000
L1.Burgenland 0.047381 0.018400 2.575 0.010
L1.Kärnten -0.017246 0.009803 -1.759 0.079
L1.Niederösterreich 0.197177 0.038471 5.125 0.000
L1.Oberösterreich 0.279063 0.036583 7.628 0.000
L1.Salzburg 0.120179 0.019508 6.161 0.000
L1.Steiermark 0.101765 0.025582 3.978 0.000
L1.Tirol 0.123541 0.020739 5.957 0.000
L1.Vorarlberg 0.069079 0.017877 3.864 0.000
L1.Wien -0.026509 0.032685 -0.811 0.417
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130242 0.048469 2.687 0.007
L1.Burgenland -0.049345 0.033312 -1.481 0.139
L1.Kärnten -0.039459 0.017747 -2.223 0.026
L1.Niederösterreich 0.167611 0.069648 2.407 0.016
L1.Oberösterreich 0.139398 0.066230 2.105 0.035
L1.Salzburg 0.285212 0.035317 8.076 0.000
L1.Steiermark 0.032469 0.046314 0.701 0.483
L1.Tirol 0.163127 0.037546 4.345 0.000
L1.Vorarlberg 0.103733 0.032365 3.205 0.001
L1.Wien 0.068647 0.059174 1.160 0.246
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058726 0.038384 1.530 0.126
L1.Burgenland 0.042573 0.026380 1.614 0.107
L1.Kärnten 0.049713 0.014054 3.537 0.000
L1.Niederösterreich 0.227311 0.055156 4.121 0.000
L1.Oberösterreich 0.272307 0.052449 5.192 0.000
L1.Salzburg 0.058146 0.027968 2.079 0.038
L1.Steiermark -0.006741 0.036677 -0.184 0.854
L1.Tirol 0.156251 0.029734 5.255 0.000
L1.Vorarlberg 0.068127 0.025630 2.658 0.008
L1.Wien 0.074122 0.046861 1.582 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185153 0.045945 4.030 0.000
L1.Burgenland -0.004525 0.031577 -0.143 0.886
L1.Kärnten -0.060916 0.016823 -3.621 0.000
L1.Niederösterreich -0.086564 0.066021 -1.311 0.190
L1.Oberösterreich 0.191741 0.062781 3.054 0.002
L1.Salzburg 0.059660 0.033478 1.782 0.075
L1.Steiermark 0.225859 0.043902 5.145 0.000
L1.Tirol 0.494987 0.035591 13.908 0.000
L1.Vorarlberg 0.047632 0.030679 1.553 0.121
L1.Wien -0.051021 0.056092 -0.910 0.363
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158612 0.052351 3.030 0.002
L1.Burgenland -0.009194 0.035980 -0.256 0.798
L1.Kärnten 0.064791 0.019168 3.380 0.001
L1.Niederösterreich 0.202630 0.075226 2.694 0.007
L1.Oberösterreich -0.067009 0.071534 -0.937 0.349
L1.Salzburg 0.222365 0.038146 5.829 0.000
L1.Steiermark 0.113432 0.050024 2.268 0.023
L1.Tirol 0.084145 0.040553 2.075 0.038
L1.Vorarlberg 0.122225 0.034957 3.496 0.000
L1.Wien 0.109803 0.063913 1.718 0.086
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357026 0.030859 11.570 0.000
L1.Burgenland 0.008784 0.021209 0.414 0.679
L1.Kärnten -0.024784 0.011299 -2.193 0.028
L1.Niederösterreich 0.228091 0.044343 5.144 0.000
L1.Oberösterreich 0.157791 0.042167 3.742 0.000
L1.Salzburg 0.053241 0.022485 2.368 0.018
L1.Steiermark -0.018174 0.029487 -0.616 0.538
L1.Tirol 0.117672 0.023904 4.923 0.000
L1.Vorarlberg 0.071613 0.020605 3.475 0.001
L1.Wien 0.050050 0.037674 1.328 0.184
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043776 0.161072 0.192579 0.165654 0.131934 0.124424 0.070001 0.230974
Kärnten 0.043776 1.000000 0.001970 0.131613 0.045047 0.099292 0.427792 -0.050584 0.101930
Niederösterreich 0.161072 0.001970 1.000000 0.345373 0.166467 0.311060 0.127864 0.192088 0.341146
Oberösterreich 0.192579 0.131613 0.345373 1.000000 0.235927 0.340634 0.177869 0.180021 0.275728
Salzburg 0.165654 0.045047 0.166467 0.235927 1.000000 0.153327 0.145164 0.152582 0.140351
Steiermark 0.131934 0.099292 0.311060 0.340634 0.153327 1.000000 0.163220 0.148366 0.092400
Tirol 0.124424 0.427792 0.127864 0.177869 0.145164 0.163220 1.000000 0.121984 0.164294
Vorarlberg 0.070001 -0.050584 0.192088 0.180021 0.152582 0.148366 0.121984 1.000000 0.019796
Wien 0.230974 0.101930 0.341146 0.275728 0.140351 0.092400 0.164294 0.019796 1.000000